package com.liangxy.news.ui.main.home;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

/**
 * Adapter for news categories in ViewPager2
 */
public class NewsCategoryAdapter extends FragmentStateAdapter {
    
    private final List<String> categories;
    
    /**
     * Constructor
     * @param fragment Parent fragment
     * @param categories List of news categories
     */
    public NewsCategoryAdapter(@NonNull HomeFragment fragment, List<String> categories) {
        super(fragment);
        this.categories = categories;
    }
    
    @NonNull
    @Override
    public Fragment createFragment(int position) {
        // Create a new news list fragment for each category
        return NewsCategoryFragment.newInstance(categories.get(position));
    }
    
    @Override
    public int getItemCount() {
        return categories.size();
    }
}